/*
 *@brief consistent_hash.h
 */
#ifndef CONSISTENT_HASH_H
#define CONSISTENT_HASH_H

#include "php.h"
#include "common_hash.h"
#include "array_op.h"

#define CONSISTENT_HASH_REPLICAS 64
#define CONSISTENT_HASH_TABLE_PERSISTENT 0 
#define CONSISTENT_HASH_TABLE_IDENTIFIER "CHASH_TMP_ID" 

typedef struct _consistent_hash_table_node{
  HashTable * ht; //the hash table to store the sorted array elements.
  zend_bool is_sorted; 
} consistent_hash_table_node;

static zend_bool consistent_hash_add_target(consistent_hash_table_node* ht_node, zval * target, uint replicas, zend_bool persistent);

static zend_bool consistent_hash_sort_targets_by_position(consistent_hash_table_node * ht_node);

zval * consistent_hash_lookup_impl(consistent_hash_table_node* ht_node, const char* key);

consistent_hash_table_node * consistent_hash_init_impl(zval * input, zend_bool persistent, const char * identifier, uint replicas);


#endif /*CONSISTENT_HASH_H*/
